<?php
/*
 *  Maniter: A webbased business managment tool.
 *  Copyright (C) 2007  Dimitri Michaux <dimitri.michaux@gmail.com>
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * calendar.php, Maniter
 * 
 * This page generates the calendar and handles everything about it.
 *
 * @author Dimitri Michaux
 * @version 0.1
 * @package maniter_core
 */

require_once( 'lib-common.php' );
require_once( _PATH_TO_JIBA.'calendar.class.php' );
require_once( 'classes/appointment.class.php' );

if( isset($_POST['action']) && $_POST['action'] == 'new' )
{
  $app = Appointment::create();
  
  $app->setSubject( $_POST['subject'] );
  $app->setDescription( $_POST['description'] );
  $app->gettimestamp()->setTime( $_POST['month'], $_POST['day'], $_POST['year'], $_POST['hour'], $_POST['minutes'] );
  
  Appointment::save( $app );
}
elseif( isset($_POST['action']) && $_POST['action'] == 'edit' && isset($_POST['id']) && strlen($_POST['id'])==32 )
{
  $app = Appointment::getById( $_POST['id'] );
  
  $app->setSubject( $_POST['subject'] );
  $app->setDescription( $_POST['description'] );
  $app->getTimestamp()->setTime( $_POST['month'], $_POST['day'], $_POST['year'], $_POST['hour'], $_POST['minutes'] );
  
  Appointment::save( $app );
}

if( isset($_GET['m']) )
  $month = $_GET['m'];
else
  $month = 0;
  
if( isset($_GET['d']) )
  $day = $_GET['d'];
else
  $day = 0;

if( isset($_GET['y']) )
  $year = $_GET['y'];
else
  $year = 0;

$tpl->calendarPage( $month, $day, $year );
?>